<template>
  <div class="count">
    <h2>当前求和为: {{sum}}, 放大十倍后: {{bigSum}}</h2>
    <h3>欢迎来到: {{school}}, 坐落于: {{address}}, 大写: {{upperSchool}}</h3>
    <select v-model="n">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
    </select>
    <button @click="add">加</button>
    <button @click="minus">减</button>
  </div>
</template>

<script setup lang="ts" name="Count">
import {ref} from "vue";
import useCountStore from '@/stores/count'
import {storeToRefs} from "pinia";

const countStore = useCountStore()
// storeToRefs只会关注store中的数据, 不会对方法进行ref包裹
let {sum, school, address, bigSum, upperSchool} = storeToRefs(countStore)

let n = ref(2)

function add() {
  // 第一种 修改方式
  // countStore.sum += n.value
  // 第二种 对象式
  // countStore.$patch({
  //   sum: countStore.sum + n.value,
  //   school: '复旦',
  //   address: '上海'
  // })
  // 第三种, actions
  countStore.increment(n.value)
}
function minus() {
  countStore.sum -= n.value
}

</script>

<style scoped>
  .count {
    background-color: skyblue;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
  }
  select, button {
    /* 上下, 左右*/
    margin: 0 5px;
    height: 25px;
  }
</style>